//
//  BettingView.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/10/19.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "BettingView.h"

@interface BettingView ()<UIScrollViewDelegate>

@property(nonatomic, strong) NSArray*arr;

#define Start_X          22.0f      // 第一个按钮的X坐标
#define Start_Y          0.0f     // 第一个按钮的Y坐标
#define Width_Space      20.0f      // 2个按钮之间的横间距
#define Height_Space     40.0f     // 竖间距
#define Button_Height   30.0f    // 高
#define Button_Width    75.0f    // 宽


@end

@implementation BettingView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self addSubview:self.view];
        //滚动视图
        [self.view addSubview:self.scrollView];
        //文字
        [self.view addSubview:self.yazhuLabel];
        [self.view addSubview:self.yazhuNumLabel];
        //确定
        [self addSubview:self.determine];
        
        
        //想点数量按钮
        _arr=@[@"5",@"10",@"15",@"20",@"25",@"30",@"35",@"40",@"45",@"50",@"55",@"60",@"65",@"70",@"75",@"80",@"85",@"90",@"95",@"100"];
        
        for (int i = 0 ; i < _arr.count; i++) {
            NSInteger index = i % 3;
            NSInteger page = i / 3;
            
            // 圆角按钮
            UIButton *mapBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            
            mapBtn.tag = i+400;//这句话不写等于废了
            mapBtn.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
            //[mapBtn setBackgroundImage:[UIImage imageNamed:arr[index]] forState:UIControlStateNormal];
            mapBtn.layer.borderWidth=1;
            mapBtn.layer.borderColor=[UIColor whiteColor].CGColor;
            mapBtn.layer.cornerRadius=kWidthScale(15);
            [mapBtn setTitle:[NSString stringWithFormat:@"%@",_arr[i]] forState:UIControlStateNormal];
            [mapBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            //mapBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
            mapBtn.titleLabel.font=[UIFont systemFontOfSize:kWidthScale(15)];
            
            [self.scrollView addSubview:mapBtn];
            //按钮点击方法
            [mapBtn addTarget:self action:@selector(mapBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }


        [self setViewUp];
    
    }
    
    return self;
}
//点击按钮方法,这里容易犯错
-(void)mapBtnClick:(UIButton *)sender{
    //记住,这里不能写成"mapBtn.tag",这样你点击任何一个button,都只能获取到最后一个button的值,因为前边的按钮都被最后一个button给覆盖了
    for (int i = 0; i <= _arr.count; i++) {
        UIButton *btn = [self viewWithTag:i+400];
        
        if(btn.tag!=sender.tag){
            btn.backgroundColor=[UIColor clearColor];
            btn.enabled=YES;
        }else {
            btn.backgroundColor=[UIColor colorWithRed:(162.0/255) green:(162.0/255) blue:(162.0/255) alpha:1];
            btn.enabled=YES;
        }
    }
    
    
    
    //NSLog(@"%ld",sender.tag);
}

  

- (void)setViewUp
{
    //View
    _view.sd_layout
    .topSpaceToView(self, kHeightScale(304/2))
    .rightSpaceToView(self, kWidthScale(65/2))
    .leftSpaceToView(self, kWidthScale(65/2))
    .heightIs(kHeightScale(590/2));
    //文字
    _yazhuLabel.sd_layout
    .topSpaceToView(self.view, kHeightScale(58/2))
    .leftSpaceToView(self.view, kWidthScale(60))
    .rightSpaceToView(self.view, kWidthScale(60))
    .autoHeightRatio(0);
    _yazhuNumLabel.sd_layout
    .topSpaceToView(self.scrollView, kHeightScale(40/2))
    .leftSpaceToView(self.view, kWidthScale(190/2))
    .rightSpaceToView(self.view, kWidthScale(190/2))
    .autoHeightRatio(0);
    //滚动视图
    _scrollView.sd_layout
    .topSpaceToView(self.view, kHeightScale(144/2))
    .leftSpaceToView(self.view, 0)
    .rightSpaceToView(self.view, 0)
    .heightIs(kHeightScale(345/2));
    //确定
    _determine.sd_layout
    .topSpaceToView(self.view, kHeightScale(25))
    .leftSpaceToView(self, kWidthScale(152/2))
    .rightSpaceToView(self, kWidthScale(152/2))
    .heightIs(kHeightScale(88/2));

    
    
}

- (UIView *)view
{
    if (!_view)
    {
        _view=[[UIView alloc] init];
        _view.layer.borderWidth=1;
        _view.layer.borderColor=[UIColor whiteColor].CGColor;
        _view.layer.masksToBounds=YES;
        _view.layer.cornerRadius=kWidthScale(20);
        
    }
    return _view;
}
//滚动视图
- (UIScrollView *)scrollView
{
    if (!_scrollView)
    {
        //滚动视图
        _scrollView=[[UIScrollView alloc] init];
        _scrollView.contentSize=CGSizeMake(self.view.frame.size.width, kHeightScale(460));
        _scrollView.delegate=self;
        //_scrollView.backgroundColor=[UIColor orangeColor];

    }
    return _scrollView;
}
//文字
- (UILabel *)yazhuLabel
{
    if (!_yazhuLabel)
    {
        _yazhuLabel=[[UILabel alloc] init];
        _yazhuLabel.text=@"您已选择代表正方进行辩论";
        _yazhuLabel.textColor=[UIColor whiteColor];
        _yazhuLabel.font=[UIFont systemFontOfSize:kWidthScale(15)];
        _yazhuLabel.textAlignment=NSTextAlignmentCenter;
        //_yazhuLabel.backgroundColor=[UIColor yellowColor];
    }
    return _yazhuLabel;
}
//文字
- (UILabel *)yazhuNumLabel
{
    if (!_yazhuNumLabel)
    {
        _yazhuNumLabel=[[UILabel alloc] init];
        _yazhuNumLabel.text=@"请选择押注想点数额";
        _yazhuNumLabel.textColor=[UIColor whiteColor];
        _yazhuNumLabel.font=[UIFont systemFontOfSize:kWidthScale(13)];
        _yazhuNumLabel.textAlignment=NSTextAlignmentCenter;
        //_yazhuLabel.backgroundColor=[UIColor yellowColor];
    }
    return _yazhuNumLabel;
}

//确定按钮
- (UIButton *)determine
{
    if (!_determine)
    {
        _determine=[[UIButton alloc] init];
        _determine.layer.borderWidth=1;
        _determine.layer.borderColor=[UIColor whiteColor].CGColor;
        [_determine setTitle:@"确定" forState:UIControlStateNormal];
        _determine.titleLabel.font=[UIFont systemFontOfSize:kWidthScale(15)];
        _determine.titleLabel.textAlignment=NSTextAlignmentCenter;
        _determine.layer.masksToBounds=YES;
        _determine.layer.cornerRadius=kWidthScale(20);
        
    }
    return _determine;
}




@end
